using System;
using System.Collections;
using System.Collections.Generic;


public class UNotifyMsg
{
    ////////////////////战斗过程相关///////////////////////////////////////////
    public const string Msg_TacticChooseTime = "Msg_TacticChooseTime";              //显示倒计时
    public const string Msg_TacticChooseTimeEnd = "Msg_TacticChooseTimeEnd";        //关闭倒计时
    public const string Msg_TacticIconShow = "Msg_TacticIconShow";                  //显示双方战术or战法图标
    public const string Msg_TacticIconSingle = "Msg_TacticIconSingle";
    public const string Msg_TacticIconDie = "Msg_TacticIconDie";
    public const string Msg_TacticCastSkillUI = "Msg_TacticCastSkillUI";
    public const string Msg_TacticCrashUI = "Msg_TacticCrashUI";
    public const string Msg_UpdateHP = "Msg_UpdateHP";
    public const string Msg_UpdateTactic = "Msg_UpdateTactic";
    public const string Msg_UpdateFightHead = "Msg_UpdateFightHead";
    public const string Msg_UpdateHeroNumChange = "Msg_UpdateHeroNumChange";
    public const string Msg_UpdateHeroLstChange = "Msg_UpdateHeroLstChange";
    public const string Msg_UpdateHeroLst = "Msg_UpdateHeroLst";
    public const string Msg_FightRoundReward = "Msg_FightRoundReward";
    public const string Msg_FightSelectTacticEnd = "Msg_FightSelectTacticEnd";
    public const string Msg_FightUIHide = "Msg_FightUIHide";
    public const string Msg_FightSoundEffect = "Msg_FightSoundEffect";
    public const string Msg_FightUIDestroy = "Msg_FightUIDestroy";
    public const string Msg_ClickLeftTeamLst = "Msg_ClickLeftTeamLst";
    public const string Msg_ClickRightTeamLst = "Msg_ClickRightTeamLst";
    public const string Msg_ClickLeftFunLst = "Msg_ClickLeftFunLst";
    public const string Msg_ClickRightFunLst = "Msg_ClickRightFunLst";
    public const string Msg_ClickBackBtn = "Msg_ClickBackBtn";
    public const string Msg_AttractEnemyCMD = "Msg_AttractEnemyCMD";
    public const string Msg_TacticAnimEvent = "Msg_TacticAnimEvent";
    public const string Msg_FightRoundOver = "Msg_FightRoundOver";
    public const string Msg_FightSoldierMoveEnd = "Msg_FightSoldierMoveEnd";
    public const string Msg_FightPreChangeCardOrder = "Msg_FightPreChangeCardOrder";

    ////////////////////战斗协议相关///////////////////////////////////////////
    public const string Msg_PreFightCMD = "Msg_PreFightCMD";
    public const string Msg_FogFightBeginCMD = "Msg_FogFightBeginCMD";
    public const string Msg_PreFightHeroTimes = "Msg_PreFightHeroTimes";
    public const string Msg_PreFightHeroAddCount = "Msg_PreFightHeroAddCount";
    public const string Msg_PreFightTerrainType = "Msg_PreFightTerrainType";
    public const string Msg_AutoCombatCMD = "Msg_AutoCombatCMD";
    public const string Msg_Combat_Try_Result = "Msg_Combat_Already_End";
    public const string Msg_Fight_Skip_Result = "Msg_Fight_Skip_Result";
    public const string Msg_FightBeginCMD = "Msg_FightBeginCMD";
    public const string Msg_FightStateBeginCMD = "Msg_FightStateBeginCMD";
    public const string Msg_FightEndCMD = "Msg_FightEndCMD";
    public const string Msg_Show_Battle_End = "Msg_Show_Battle_End";
    public const string Msg_Fight_Skip_Failed = "Msg_Fight_Skip_Failed";
    public const string Msg_Update_Fight_Condition = "Msg_Update_Fight_Condition";

    ////////////////////其他///////////////////////////////////////////////////
    public const string Msg_OpenMenuOrBuildindCMD = "Msg_OpenControlCMD";
    public const string Msg_RefreshBuildingProduction = "Msg_RefreshBuildingProduction";
    public const string Msg_BuildingLevelUpState = "Msg_BuildingLevelUpState";
    public const string Msg_OpenFuncCMD = "Msg_OpenFuncCMD";
    public const string Msg_HideTargetCMD = "Msg_HideTargetCMD";
    public const string Msg_DragCameraBeginCMD = "Msg_DragCameraBeginCMD";
    public const string Msg_DragCameraEndCMD = "Msg_DragCameraEndCMD";
    public const string Msg_ShowUnLockArmyCMD = "Msg_ShowUnLockArmyCMD";
    public const string Msg_OnCustomScrollViewSpring = "Msg_OnCustomScrollViewSpring";
    public const string Msg_CountryTask_Notice = "Msg_CountryTask_Notice";

    //////////////////////GameStart////////////////////////////////////////////////
    public const string Msg_GameStart_UpdateEnd = "Msg_GameStart_UpdateEnd";
    public const string Msg_GameStart_LoginStart = "Msg_GameStart_LoginStart";
    public const string Msg_GameStart_LoginEnd = "Msg_GameStart_LoginEnd";

    //测试政务
    public const string Msg_ShowZhengwuCMD = "Msg_ShowZhengwuCMD";

    //测试限时商店
    public const string Msg_ShowLimitShop = "Msg_ShowLimitShop";

    //////////////////////卡片相关////////////////////////////////////////////////
    public const string Msg_CardStatusChange = "Msg_CardStatusChange";
    ////////////////////开启动画播放结束///////////////////////////////////////////
    public const string Msg_OpenUnLockFinishCMD = "Msg_OpenUnLockFinishCMD";
    ////////////////////开启按钮播放///////////////////////////////////////////
    public const string Msg_OpenBtnUnLockFinishCMD = "Msg_OpenBtnUnLockFinishCMD";
    ////////////////////UI特效相关///////////////////////////////////////////
    public const string Msg_UIClickEffect = "Msg_UIClickEffect";
    public const string Msg_UIEffectLoaded = "Msg_UIEffectLoaded";
    public const string Msg_UIToolTip = "Msg_UIToolTip";
    ////////////////////寻路逻辑相关//////////////////////////////////////////////
    public const string Msg_StopConveneCMD = "Msg_StopConveneCMD";
    /////////////////////主界面相关//////////////////////////////////////////////
    public const string Msg_OpenBtnZoom = "Msg_OpenBtnZoom";
    public const string Msg_HandleLastLoginInitMsg = "Msg_HandleLastLoginInitMsg";
    /////////////////////指引提醒光标//////////////////////////////////////////////
    public const string Msg_RemindCursor = "Msg_RemindCursor";
    /////////////////////世界/按钮光标//////////////////////////////////////////////
    public const string Msg_BtnWorldCursor = "Msg_BtnWorldCursor";
    /////////////////////世界按钮特效//////////////////////////////////////////////
    public const string Msg_BtnWorldVfx = "Msg_BtnWorldVfx";
    //////////////////////关卡滑动/////////////////////////////////////////////
    public const string Msg_SetStageScrolViewCMD = "Msg_SetStageScrolViewCMD";
    //////////////////////隐藏主线任务按钮/////////////////////////////////////////////
    public const string Msg_HideMainTaskBtn = "Msg_HideMainTaskBtn";
    //////////////////////刷新主界面功能预告按钮/////////////////////////////////////////////
    public const string Msg_UpdateFunNotice = "Msg_UpdateRemind";
    ///////////////////国家任务////////////////////////////////////////////////
    public const string Msg_Att_Def_Task_Fresh = "Msg_Att_Def_Task_Fresh";
    //////////////////////////断线重连/////////////////////////////////////////////////////
    public const string Msg_ReConnect = "Msg_ReConnect";
    public const string Msg_CallUp = "Msg_CallUp";
    public const string Msg_ManCallUp = "Msg_Man_CallUp";
    public const string Msg_ReConnect_RefreshBaseModuleReq = "Msg_ReConnect_RefreshBaseModuleReq";
    public const string Msg_ReConnect_RefreshBaseModuleResp = "Msg_ReConnect_RefreshBaseModuleResp";
    //////////////////////////功能提醒/////////////////////////////////////////////////////
    public const string Msg_AddRemind = "Msg_AddRemind";
    public const string Msg_RemoveRemind = "Msg_RemoveRemind";
    public const string Msg_UpdateMenuRemind = "Msg_UpdateMenuRemind";
    //////////////////////////活动主界面显示/////////////////////////////////////////////////////
    public const string Msg_ShowActivityIcon = "Msg_ShowActivityIcon";
    //////////////////////////揭开迷雾主界面显示/////////////////////////////////////////////////////
    public const string Msg_OpenFogIcon = "Msg_OpenFogIcon";
    //////////////////////////通关送钻主界面显示/////////////////////////////////////////////////////
    public const string Msg_TGDiamondIcon = "Msg_TGDiamondIcon";
    /////////////////////主界面点击空白////////////////////////////////////////
    public const string Msg_MenuClickEmpty = "Msg_MenuClickEmpty";
    //////////////////////Sdk相关/////////////////////////////////////////////////////
    public const string Msg_Sdk_Ch_ShowDialog_ByLogin = "Msg_Sdk_Ch_ShowDialog_ByLogin";
    public const string Msg_Sdk_Ch_ShowDialog_ByMenu = "Msg_Sdk_Ch_ShowDialog_ByMenu";
    public const string Msg_Sdk_Ch_RoleLevel_Change = "Msg_Sdk_Ch_RoleLevel_Change";
    //////////////////////世界相关/////////////////////////////////////////////////////

    public const string Msg_CityMenuOnShowCMD = "Msg_CityMenuOnShowCMD";
    public const string Msg_CityMenuOnHideCMD = "Msg_CityMenuOnHideCMD";
    public const string Msg_TuntianMenuHideCMD = "Msg_TuntianMenuHideCMD";
    public const string Msg_MiniMapHideCMD = "Msg_MiniMapHideCMD";
    public const string Msg_MiniMapShowCMD = "Msg_MiniMapShowCMD";
    public const string Msg_UnLockFogShowCMD = "Msg_UnLockFogShowCMD";//解锁迷雾通知
    public const string Msg_UpdateCityFireEffect = "Msg_UpdateCityFireEffect";
    public const string Msg_UpdateNpcShowTime = "Msg_UpdateNpcShowTime";
    public const string Msg_UpdateParadeCD = "Msg_UpdateParadeCD";
    public const string Msg_UpdateCityCountryChange = "Msg_UpdateCityCountryChange";
    public const string Msg_UpdateCountryBounds = "Msg_UpdateCountryBounds";
    public const string Msg_UpdateCityCountry = "Msg_UpdateCityCountry";
    public const string Msg_UpdateCityJiCe = "Msg_UpdateCityJiCe";
    public const string Msg_UpdateCityEncircled = "Msg_UpdateCityEncircled";
    //////////////////////武将移动/////////////////////////////////////////////////////
    public const string Msg_MoveActorEatSpot = "Msg_MoveActorEatSpot";
    public const string Msg_MoveActorArriveCity = "Msg_MoveActorArriveCity";
    public const string Msg_MoveActorArriveCityLate = "Msg_MoveActorArriveCityLate";
    public const string Msg_MoveActorLeaveCity = "Msg_MoveActorLeaveCity";
    public const string Msg_MoveActorStopMove = "Msg_MoveActorStopMove";
    public const string Msg_MoveActorMoveEnd = "Msg_MoveActorMoveEnd";
    public const string Msg_NPC_Convene = "Msg_NPC_Convene";
    public const string Msg_Npc_Del = "Msg_Npc_Del";
    public const string Msg_Npc_Show = "Msg_Npc_Show";
    public const string Msg_Npc_Hide = "Msg_Npc_Hide";
    public const string Msg_PreFightHeroAddBack = "Msg_PreFightHeroAddBack";

    ////////////////////世界教学///////////////////////////////////////////////////
    public const string Msg_Update_Main_Task = "Msg_Update_Main_Task";
    public const string Msg_Hero_Is_Dead = "Msg_Hero_Is_Dead";
    public const string Msg_Update_Teach_State = "Msg_Update_Teach_State";
    public const string Msg_Update_Teach_Guide = "Msg_Update_Teach_Guide";
    public const string Msg_Send_Teach_Guide = "Msg_Send_Teach_Guide";
    public const string Msg_Update_Guanzhan_View = "Msg_Update_Guanzhan_View";
    public const string Msg_OnClick_Guanzhan_Button = "Msg_OnClick_Guanzhan_Button";
    public const string Msg_In_Teach_Fight_View = "Msg_In_Teach_Fight_View";
    public const string Msg_OnClick_Youdi_Button = "Msg_OnClick_Youdi_Button";
    public const string Msg_OnClick_Zengbing_Button = "Msg_OnClick_Zengbing_Button";
    public const string Msg_OnClick_Tujing_Button = "Msg_OnClick_Tujing_Button";
    public const string Msg_Leave_Teach_Fight = "Msg_Leave_Teach_Fight";
    public const string Msg_Enter_Teach_Fight = "Msg_Enter_Teach_Fight";

    ////////////////////////////////聊天///////////////////////////////////////////
    public const string Msg_ShowNewChatInfo = "Msg_ShowNewChatInfo";
    public const string Msg_BuildingNotice = "Msg_BuildingNotice";
}


public delegate void UNotifyHandler(string msg, params object[] param);
public class UNotifyCenter
{
    #region 静态函数
    public static UNotifyCenter SharedNotifyCenter()
    {
        if (s_sharedNotifCenter == null)
        {
            s_sharedNotifCenter = new UNotifyCenter();
            if (s_sharedNotifCenter.m_observers == null)
            {
                s_sharedNotifCenter.m_observers = new List<UNotifyObserver>();
            }
        }
        return s_sharedNotifCenter;
    }
    public static void addObserver(string name, UNotifyHandler handler)
    {
        SharedNotifyCenter().AddObserver(name, handler);
    }
    public static void removeObserver(string name, UNotifyHandler handler)
    {
        SharedNotifyCenter().RemoveObserver(name, handler);
    }
    public static void postNotification(string name, params object[] param)
    {
        SharedNotifyCenter().PostNotification(name, param);
    }

    #endregion

    public void PurgeNotifyCenter()
    {
        m_observers.Clear();
    }


    public void AddObserver(string name, UNotifyHandler handler)
    {
        if (ObserverExisted(name, handler) >= 0)
        {
            return;
        }

        UNotifyObserver observer = new UNotifyObserver(name, handler);
        if (observer == null)
        {
            return;
        }

        m_observers.Add(observer);
    }


    public void RemoveObserver(string name, UNotifyHandler handler)
    {
        if (name == null || handler == null)
        {
            return;
        }

        int index = ObserverExisted(name, handler);
        if (index >= 0)
        {
            m_observers.RemoveAt(index);
        }
    }



    /*remove all notification by name*/
    public void RemoveObserver(string name)
    {
        if (name == null)
        {
            return;
        }

        List<UNotifyObserver> newObservers = new List<UNotifyObserver>();
        int count = m_observers.Count;
        for (int index = 0; index < count; index++)
        {
            UNotifyObserver observer = m_observers[index];
            if (observer.GetName() != name)
            {
                newObservers.Add(observer);
            }
        }

        m_observers = newObservers;
    }

    public void PostNotification(string name)
    {
        PostNotification(name, 0);
    }

    public void PostNotification(string name, params object[] param)
    {
        List<UNotifyObserver> tmp_observers = new List<UNotifyObserver>();
        tmp_observers.AddRange(m_observers);

        int count = tmp_observers.Count;
        for (int index = 0; index < count; index++)
        {
            UNotifyObserver observer = tmp_observers[index];
            if (observer.GetName() == name)
            {
                observer.PerformSelector(param);
            }
        }
    }

    #region protected method
    protected UNotifyCenter()
    {
        //m_observers = new List<UNotificationObserver>();
    }

    protected int ObserverExisted(string name, UNotifyHandler handler)
    {
        int count = m_observers.Count;
        for (int index = 0; index < count; index++)
        {
            UNotifyObserver observer = m_observers[index];
            if (observer.GetName() == name && observer.GetHandler() == handler)
            {
                return index;
            }
        }

        return -1;
    }



    protected List<UNotifyObserver> m_observers = null;
    protected static UNotifyCenter s_sharedNotifCenter = null;
    #endregion
};


/// <summary>
/// Unotification observer.//////////////////////////////////////////////////////////////////////////
/// </summary>
public class UNotifyObserver
{
    public UNotifyObserver(string name, UNotifyHandler handler)
    {
        m_handler = handler;
        m_name = name;
        FuncType = 1;
    }



    public void PerformSelector(object[] param)
    {
        if (m_name == null)
        {
            return;
        }

        if (m_handler != null)
        {
            m_handler(m_name, param);
        }
    }

    public UNotifyHandler GetHandler()
    {
        return m_handler;
    }


    public string GetName()
    {
        return m_name;
    }

    #region protected method
    protected string m_name;
    protected UNotifyHandler m_handler;

    public int FuncType;
    #endregion

};
